Script to analyze larval size, symbiont density, and examine correlations between physiological responses.
Set up workspace, set options, and load required packages.
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
Volume is calculated as an elliptical sphere using the length and width measurements of each individual.
# Larval size data
size <- read_csv("Mcap2020/Data/Physiology/Size/larval_volume.csv")
#metadata
metadata <- read_csv("Mcap2020/Data/lifestage_metadata.csv")
# select columns
size <- size %>%
dplyr::select(tube.ID, code, replicate, volume)%>%
drop_na() #remove na's that could not be measured
size$replicate<-as.factor(size$replicate)
size$tube.ID<-as.factor(size$tube.ID)
size$code<-as.factor(size$code)
size$hpf<-metadata$hpf[match(size$code, metadata$code)]
size$group<-metadata$group[match(size$code, metadata$code)]
size$lifestage<-metadata$lifestage[match(size$code, metadata$code)]
#change metamorphosed recruit to metamorphosed polyp
size$group <- if_else(size$group == "Metamorphosed Recruit", "Metamorphosed Polyp", size$group)
size$lifestage <- if_else(size$lifestage == "Metamorphosed Recruit (231 hpf)", "Metamorphosed Polyp (231 hpf)", size$lifestage)
size$lifestage <- if_else(size$lifestage == "Metamorphosed Recruit (183 hpf)", "Metamorphosed Polyp (183 hpf)", size$lifestage)
size$hpf <- as.factor(size$hpf)
size$group <- as.factor(size$group)
size$lifestage <- as.factor(size$lifestage)
Prep data frame.
# Calculate mean counts for each sample
size <- size %>%
dplyr::select(tube.ID, lifestage, replicate, volume, hpf, group, code)%>%
drop_na() #remove na's that could not be measured
Plot data with mean and standard error for each lifestage.
size %>%
ggplot(aes(x = hpf, y = volume, color = group)) +
labs(x = "",y = "Mean Larval Volume (mm^3)") +
geom_jitter(width = 0.1) + # Plot all points
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), # Plot standard error
geom = "errorbar", color = "black", width = 0.5) +
stat_summary(fun = mean, geom = "point", color = "black") + # Plot mean
theme_classic()
Present means and standard error of each group and save summary table
size%>%
group_by(lifestage, hpf)%>%
summarise(n=length(volume),
Mean=format(round(mean(volume), 3), 3),
SE=format(round(sd(volume)/sqrt(length(volume)),3),3))%>%
rename(Lifestage=lifestage, HPF=hpf)%>%
kbl(caption="Descriptive statistics of larval volume across ontogeny")%>%
kable_classic(full_width=FALSE, html_font="Arial")%>%
row_spec(0, bold = TRUE)
| Lifestage | HPF | n | Mean | SE |
|---|---|---|---|---|
| Egg (1 hpf) | 1 | 60 | 0.1 | 0.002 |
| Embryo (38 hpf) | 38 | 60 | 0.122 | 0.003 |
| Embryo (5 hpf) | 5 | 60 | 0.09 | 0.002 |
| Embryo (65 hpf) | 65 | 60 | 0.067 | 0.003 |
| Larvae (163 hpf) | 163 | 60 | 0.093 | 0.002 |
| Larvae (183 hpf) | 183 | 60 | 0.1 | 0.003 |
| Larvae (231 hpf) | 231 | 56 | 0.15 | 0.007 |
| Larvae (93 hpf) | 93 | 60 | 0.057 | 0.003 |
| Metamorphosed Polyp (183 hpf) | 183 | 58 | 0.082 | 0.004 |
| Metamorphosed Polyp (231 hpf) | 231 | 39 | 0.124 | 0.009 |
#need to output to csv
size%>%
group_by(lifestage, hpf)%>%
summarise(n=length(volume),
Mean=format(round(mean(volume), 3), 3),
SE=format(round(sd(volume)/sqrt(length(volume)),3),3))%>%
rename(Lifestage=lifestage, HPF=hpf)%>%
write_csv(., "Mcap2020/Output/Physiology/larval_volume_table.csv")
Plot data as a scatterplot
size$hpf<-as.factor(size$hpf)
size_plot<-size %>%
ggplot(., aes(x = hpf, y = volume)) +
#geom_boxplot(outlier.size = 0) +
geom_smooth(method="loess", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(0.1)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
ylab(expression(bold(paste("Volume (mm"^3, ")"))))+
ylim(0,1)+
theme_classic() +
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14),
legend.text=element_text(size=12)
); size_plot
#EGG: #8C510A
#EMBRYO: #DFC27D
#LARVAE: #80CDC1
#RECRUIT: #003C30
size_plot2<-size %>%
ggplot(., aes(x = hpf, y = volume)) +
geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
geom_point(aes(fill=group), pch = 21, size=2, position = position_jitterdodge(0.1)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
ylab(expression(bold(paste("Volume (mm"^3, ")"))))+
ylim(0, 0.8)+
theme_classic() +
#geom_text(label="A", x=1, y=2500, size=4, color="black")+ #egg
#geom_text(label="A", x=2, y=2500, size=4, color="black")+ #embryo 1
#geom_text(label="A", x=3, y=2500, size=4, color="black")+ #larvae 1
#geom_text(label="AB", x=4, y=4100, size=4, color="black")+ #larvae 2
#geom_text(label="AB", x=5, y=4100, size=4, color="black")+ #larvae 3
#geom_text(label="AB", x=6, y=4100, size=4, color="black")+ #larvae 4
#geom_text(label="BC", x=6.8, y=4500, size=4, color="black")+ #larvae 5
#geom_text(label="CD", x=7.2, y=6500, size=4, color="black")+ #recruit 1
#geom_text(label="D", x=7.8, y=6500, size=4, color="black")+ #larvae6
#geom_text(label="D", x=8.2, y=8700, size=4, color="black")+ #recruit2
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); size_plot2
Run lmer on cells per larvae by sampling point, specified by sequence of samples taken (life stage, hpf). Use tube ID as random effect.
size_model<-lmer(volume~lifestage + (1|tube.ID), data=size)
summary(size_model)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: volume ~ lifestage + (1 | tube.ID)
## Data: size
##
## REML criterion at convergence: -2330.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.5066 -0.5536 -0.0267 0.4768 8.0508
##
## Random effects:
## Groups Name Variance Std.Dev.
## tube.ID (Intercept) 1.728e-05 0.004157
## Residual 8.565e-04 0.029265
## Number of obs: 573, groups: tube.ID, 40
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 0.1000779 0.0043120 27.4844532 23.209
## lifestageEmbryo (38 hpf) 0.0219465 0.0060982 27.4844532 3.599
## lifestageEmbryo (5 hpf) -0.0100415 0.0060982 27.4844532 -1.647
## lifestageEmbryo (65 hpf) -0.0331428 0.0060982 27.4844532 -5.435
## lifestageLarvae (163 hpf) -0.0066574 0.0060982 27.4844532 -1.092
## lifestageLarvae (183 hpf) 0.0002654 0.0060982 27.4844532 0.044
## lifestageLarvae (231 hpf) 0.0493270 0.0061855 28.8072812 7.975
## lifestageLarvae (93 hpf) -0.0426358 0.0060982 27.4844532 -6.992
## lifestageMetamorphosed Polyp (183 hpf) -0.0178598 0.0061394 28.1742028 -2.909
## lifestageMetamorphosed Polyp (231 hpf) 0.0234320 0.0067441 36.5561749 3.474
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## lifestageEmbryo (38 hpf) 0.00124 **
## lifestageEmbryo (5 hpf) 0.11102
## lifestageEmbryo (65 hpf) 8.97e-06 ***
## lifestageLarvae (163 hpf) 0.28444
## lifestageLarvae (183 hpf) 0.96560
## lifestageLarvae (231 hpf) 8.97e-09 ***
## lifestageLarvae (93 hpf) 1.47e-07 ***
## lifestageMetamorphosed Polyp (183 hpf) 0.00700 **
## lifestageMetamorphosed Polyp (231 hpf) 0.00134 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) lE(38h lE(5h) lE(65h lL(16h lL(18h lL(23h lL(93h lMP(1h
## lfstgE(38h) -0.707
## lfstgE(5hp) -0.707 0.500
## lfstgE(65h) -0.707 0.500 0.500
## lfstL(163h) -0.707 0.500 0.500 0.500
## lfstL(183h) -0.707 0.500 0.500 0.500 0.500
## lfstL(231h) -0.697 0.493 0.493 0.493 0.493 0.493
## lfstgL(93h) -0.707 0.500 0.500 0.500 0.500 0.500 0.493
## lfsMP(183h) -0.702 0.497 0.497 0.497 0.497 0.497 0.490 0.497
## lfsMP(231h) -0.639 0.452 0.452 0.452 0.452 0.452 0.446 0.452 0.449
qqPlot(residuals(size_model))
## [1] 535 442
leveneTest(residuals(size_model)~lifestage, data=size)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 9 10.966 8.147e-16 ***
## 563
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(size_model, type=2)
## Type II Analysis of Variance Table with Satterthwaite's method
## Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
## lifestage 0.29801 0.033112 9 29.163 38.661 7.936e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Violation in normality and variance assumptions. Conduct non-parametric test (Kruskal Wallis).
kruskal.test(volume~lifestage, data=size)
##
## Kruskal-Wallis rank sum test
##
## data: volume by lifestage
## Kruskal-Wallis chi-squared = 266.37, df = 9, p-value < 2.2e-16
Significant difference in size between lifestages.
View posthoc comparisons for differences between lifestages.
emm = emmeans(size_model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
## lifestage emmean SE df lower.CL upper.CL .group
## Larvae (93 hpf) 0.0574 0.00431 28.0 0.0486 0.0663 A
## Embryo (65 hpf) 0.0669 0.00431 28.0 0.0581 0.0758 AB
## Metamorphosed Polyp (183 hpf) 0.0822 0.00437 29.4 0.0733 0.0912 BC
## Embryo (5 hpf) 0.0900 0.00431 28.0 0.0812 0.0989 C
## Larvae (163 hpf) 0.0934 0.00431 28.0 0.0846 0.1023 C
## Egg (1 hpf) 0.1001 0.00431 28.0 0.0912 0.1089 C
## Larvae (183 hpf) 0.1003 0.00431 28.0 0.0915 0.1092 C
## Embryo (38 hpf) 0.1220 0.00431 28.0 0.1132 0.1309 D
## Metamorphosed Polyp (231 hpf) 0.1235 0.00521 46.4 0.1130 0.1340 D
## Larvae (231 hpf) 0.1494 0.00444 30.7 0.1404 0.1585 E
##
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
## P value adjustment: tukey method for comparing a family of 10 estimates
## significance level used: alpha = 0.05
## NOTE: Compact letter displays can be misleading
## because they show NON-findings rather than findings.
## Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
pairs(emm)
## contrast estimate
## Egg (1 hpf) - Embryo (38 hpf) -0.021947
## Egg (1 hpf) - Embryo (5 hpf) 0.010042
## Egg (1 hpf) - Embryo (65 hpf) 0.033143
## Egg (1 hpf) - Larvae (163 hpf) 0.006657
## Egg (1 hpf) - Larvae (183 hpf) -0.000265
## Egg (1 hpf) - Larvae (231 hpf) -0.049327
## Egg (1 hpf) - Larvae (93 hpf) 0.042636
## Egg (1 hpf) - Metamorphosed Polyp (183 hpf) 0.017860
## Egg (1 hpf) - Metamorphosed Polyp (231 hpf) -0.023432
## Embryo (38 hpf) - Embryo (5 hpf) 0.031988
## Embryo (38 hpf) - Embryo (65 hpf) 0.055089
## Embryo (38 hpf) - Larvae (163 hpf) 0.028604
## Embryo (38 hpf) - Larvae (183 hpf) 0.021681
## Embryo (38 hpf) - Larvae (231 hpf) -0.027380
## Embryo (38 hpf) - Larvae (93 hpf) 0.064582
## Embryo (38 hpf) - Metamorphosed Polyp (183 hpf) 0.039806
## Embryo (38 hpf) - Metamorphosed Polyp (231 hpf) -0.001486
## Embryo (5 hpf) - Embryo (65 hpf) 0.023101
## Embryo (5 hpf) - Larvae (163 hpf) -0.003384
## Embryo (5 hpf) - Larvae (183 hpf) -0.010307
## Embryo (5 hpf) - Larvae (231 hpf) -0.059368
## Embryo (5 hpf) - Larvae (93 hpf) 0.032594
## Embryo (5 hpf) - Metamorphosed Polyp (183 hpf) 0.007818
## Embryo (5 hpf) - Metamorphosed Polyp (231 hpf) -0.033474
## Embryo (65 hpf) - Larvae (163 hpf) -0.026485
## Embryo (65 hpf) - Larvae (183 hpf) -0.033408
## Embryo (65 hpf) - Larvae (231 hpf) -0.082470
## Embryo (65 hpf) - Larvae (93 hpf) 0.009493
## Embryo (65 hpf) - Metamorphosed Polyp (183 hpf) -0.015283
## Embryo (65 hpf) - Metamorphosed Polyp (231 hpf) -0.056575
## Larvae (163 hpf) - Larvae (183 hpf) -0.006923
## Larvae (163 hpf) - Larvae (231 hpf) -0.055984
## Larvae (163 hpf) - Larvae (93 hpf) 0.035978
## Larvae (163 hpf) - Metamorphosed Polyp (183 hpf) 0.011202
## Larvae (163 hpf) - Metamorphosed Polyp (231 hpf) -0.030089
## Larvae (183 hpf) - Larvae (231 hpf) -0.049062
## Larvae (183 hpf) - Larvae (93 hpf) 0.042901
## Larvae (183 hpf) - Metamorphosed Polyp (183 hpf) 0.018125
## Larvae (183 hpf) - Metamorphosed Polyp (231 hpf) -0.023167
## Larvae (231 hpf) - Larvae (93 hpf) 0.091963
## Larvae (231 hpf) - Metamorphosed Polyp (183 hpf) 0.067187
## Larvae (231 hpf) - Metamorphosed Polyp (231 hpf) 0.025895
## Larvae (93 hpf) - Metamorphosed Polyp (183 hpf) -0.024776
## Larvae (93 hpf) - Metamorphosed Polyp (231 hpf) -0.066068
## Metamorphosed Polyp (183 hpf) - Metamorphosed Polyp (231 hpf) -0.041292
## SE df t.ratio p.value
## 0.00610 28.0 -3.599 0.0339
## 0.00610 28.0 1.647 0.8143
## 0.00610 28.0 5.435 0.0003
## 0.00610 28.0 1.092 0.9816
## 0.00610 28.0 -0.044 1.0000
## 0.00619 29.3 -7.972 <.0001
## 0.00610 28.0 6.992 <.0001
## 0.00614 28.7 2.909 0.1491
## 0.00676 37.2 -3.467 0.0387
## 0.00610 28.0 5.246 0.0005
## 0.00610 28.0 9.034 <.0001
## 0.00610 28.0 4.691 0.0022
## 0.00610 28.0 3.555 0.0375
## 0.00619 29.3 -4.425 0.0041
## 0.00610 28.0 10.590 <.0001
## 0.00614 28.7 6.483 <.0001
## 0.00676 37.2 -0.220 1.0000
## 0.00610 28.0 3.788 0.0217
## 0.00610 28.0 -0.555 0.9999
## 0.00610 28.0 -1.690 0.7916
## 0.00619 29.3 -9.595 <.0001
## 0.00610 28.0 5.345 0.0004
## 0.00614 28.7 1.273 0.9518
## 0.00676 37.2 -4.952 0.0006
## 0.00610 28.0 -4.343 0.0055
## 0.00610 28.0 -5.478 0.0003
## 0.00619 29.3 -13.329 <.0001
## 0.00610 28.0 1.557 0.8571
## 0.00614 28.7 -2.489 0.3153
## 0.00676 37.2 -8.370 <.0001
## 0.00610 28.0 -1.135 0.9763
## 0.00619 29.3 -9.048 <.0001
## 0.00610 28.0 5.900 0.0001
## 0.00614 28.7 1.825 0.7153
## 0.00676 37.2 -4.451 0.0027
## 0.00619 29.3 -7.929 <.0001
## 0.00610 28.0 7.035 <.0001
## 0.00614 28.7 2.952 0.1369
## 0.00676 37.2 -3.427 0.0427
## 0.00619 29.3 14.863 <.0001
## 0.00623 30.0 10.787 <.0001
## 0.00684 38.6 3.786 0.0166
## 0.00614 28.7 -4.035 0.0115
## 0.00676 37.2 -9.774 <.0001
## 0.00680 37.9 -6.075 <.0001
##
## Degrees-of-freedom method: kenward-roger
## P value adjustment: tukey method for comparing a family of 10 estimates
# Cell count data
sym_counts <- read_csv("Mcap2020/Data/Physiology/CellDensity/symbiont.counts.csv")
sym_counts<-sym_counts%>%
rename(code=lifestage)
Calculate cells and normalize to either planar size (eggs through metamorphosed recruits) or surface area (attached recruits)
# Calculate mean counts for each sample
df <- sym_counts %>%
dplyr::select(tube.ID, num.squares, matches("count[1-6]")) %>%
gather("rep", "count", -tube.ID, -num.squares) %>%
group_by(tube.ID, num.squares) %>%
summarise(mean_count = mean(count, na.rm = TRUE))
#match in identifying information
df$code<-sym_counts$code[match(df$tube.ID, sym_counts$tube.ID)]
df$total.volume.ul<-sym_counts$total.volume.ul[match(df$tube.ID, sym_counts$tube.ID)]
df$num.individuals<-sym_counts$num.individuals[match(df$tube.ID, sym_counts$tube.ID)]
df$surface.area<-sym_counts$surface.area[match(df$tube.ID, sym_counts$tube.ID)]
#add in metadata
df$hpf<-metadata$hpf[match(df$code, metadata$code)]
df$group<-metadata$group[match(df$code, metadata$code)]
df$lifestage<-metadata$lifestage[match(df$code, metadata$code)]
df$group <- if_else(df$group == "Metamorphosed Recruit", "Metamorphosed Polyp", df$group)
df$lifestage <- if_else(df$lifestage == "Metamorphosed Recruit (231 hpf)", "Metamorphosed Polyp (231 hpf)", df$lifestage)
df$lifestage <- if_else(df$lifestage == "Metamorphosed Recruit (183 hpf)", "Metamorphosed Polyp (183 hpf)", df$lifestage)
# Normalize counts by homogenate volume and surface area
df <- df %>%
mutate(cells.mL = mean_count * 10000 / num.squares,
cells = cells.mL * (total.volume.ul/1000),
cells.ind = cells / num.individuals,
cells.mm = cells / surface.area)
sym_counts<-df
Plot data with mean and standard error for larvae through metamorphosis (these counts have cells/individual). Plot attached recruits separately, these values are in cells per mm2. We will plot cells per unit surface area for all stages in later analyses.
Display cells per individual.
sym_counts %>%
filter(!group=="Attached Recruit")%>%
ggplot(aes(x = lifestage, y = cells.ind, color = group)) +
labs(x = "",y = "Cell Density per larva") +
geom_jitter(width = 0.1) + # Plot all points
stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), # Plot standard error
geom = "errorbar", color = "black", width = 0.5) +
stat_summary(fun = mean, geom = "point", color = "black") + # Plot mean
theme_classic()
Display cell density per mm2 in attached recruit plugs. Plug 1 = 48 hps, Plug 2 = 72 hps, Plug 3 = 96 hps
sym_counts %>%
filter(group=="Attached Recruit")%>%
ggplot(aes(x = lifestage, y = cells.mm, color = lifestage)) +
labs(x = "",y = "Cell Density per mm2") +
geom_jitter(width = 0.1) + # Plot all points
#stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1), # Plot standard error
#geom = "errorbar", color = "black", width = 0.5) +
#stat_summary(fun.y = mean, geom = "point", color = "black") + # Plot mean
theme_classic()
Present means and standard error of each group and save summary table.
sym_counts%>%
group_by(group, hpf, lifestage)%>%
summarise(n=length(cells.ind),
Mean=format(round(mean(cells.ind), 0), 0),
SE=format(round(sd(cells.ind)/sqrt(length(cells.ind)),0),0))%>%
rename(Lifestage=group, HPF=hpf)%>%
kbl(caption="Descriptive statistics of Symbiodiniaceae cell densities per larva across ontogeny")%>%
kable_classic(full_width=FALSE, html_font="Arial")%>%
row_spec(0, bold = TRUE)
| Lifestage | HPF | lifestage | n | Mean | SE |
|---|---|---|---|---|---|
| Attached Recruit | 183 | Attached Recruit (183 hpf) | 3 | NA | NA |
| Attached Recruit | 231 | Attached Recruit (231 hpf) | 2 | NA | NA |
| Attached Recruit | 255 | Attached Recruit (255 hpf) | 3 | NA | NA |
| Egg | 1 | Egg (1 hpf) | 4 | 1472 | 125 |
| Embryo | 5 | Embryo (5 hpf) | 4 | 1831 | 124 |
| Embryo | 38 | Embryo (38 hpf) | 4 | 1371 | 242 |
| Embryo | 65 | Embryo (65 hpf) | 4 | 2646 | 238 |
| Larvae | 93 | Larvae (93 hpf) | 4 | 2692 | 347 |
| Larvae | 163 | Larvae (163 hpf) | 4 | 2848 | 206 |
| Larvae | 183 | Larvae (183 hpf) | 4 | 3474 | 134 |
| Larvae | 231 | Larvae (231 hpf) | 4 | 5142 | 386 |
| Metamorphosed Polyp | 183 | Metamorphosed Polyp (183 hpf) | 4 | 4829 | 480 |
| Metamorphosed Polyp | 231 | Metamorphosed Polyp (231 hpf) | 4 | 6424 | 659 |
sym_counts%>%
group_by(group, hpf, lifestage)%>%
summarise(n=length(cells.mm),
Mean=format(round(mean(cells.mm), 0), 0),
SE=format(round(sd(cells.mm)/sqrt(length(cells.mm)),0),0))%>%
rename(Lifestage=group, HPF=hpf)%>%
kbl(caption="Descriptive statistics of Symbiodiniaceae cell densities per mm2 across ontogeny")%>%
kable_classic(full_width=FALSE, html_font="Arial")%>%
row_spec(0, bold = TRUE)
| Lifestage | HPF | lifestage | n | Mean | SE |
|---|---|---|---|---|---|
| Attached Recruit | 183 | Attached Recruit (183 hpf) | 3 | 3241 | 639 |
| Attached Recruit | 231 | Attached Recruit (231 hpf) | 2 | 4055 | 385 |
| Attached Recruit | 255 | Attached Recruit (255 hpf) | 3 | 6307 | 680 |
| Egg | 1 | Egg (1 hpf) | 4 | NA | NA |
| Embryo | 5 | Embryo (5 hpf) | 4 | NA | NA |
| Embryo | 38 | Embryo (38 hpf) | 4 | NA | NA |
| Embryo | 65 | Embryo (65 hpf) | 4 | NA | NA |
| Larvae | 93 | Larvae (93 hpf) | 4 | NA | NA |
| Larvae | 163 | Larvae (163 hpf) | 4 | NA | NA |
| Larvae | 183 | Larvae (183 hpf) | 4 | NA | NA |
| Larvae | 231 | Larvae (231 hpf) | 4 | NA | NA |
| Metamorphosed Polyp | 183 | Metamorphosed Polyp (183 hpf) | 4 | NA | NA |
| Metamorphosed Polyp | 231 | Metamorphosed Polyp (231 hpf) | 4 | NA | NA |
#need to output to csv
sym_counts%>%
group_by(group, hpf, lifestage)%>%
summarise(n=length(cells.ind),
Mean=format(round(mean(cells.ind), 0), 0),
SE=format(round(sd(cells.ind)/sqrt(length(cells.ind)),0),0))%>%
rename(group=group, HPF=hpf)%>%
write_csv(., "Mcap2020/Output/Physiology/cell_density_table.csv")
Plot data as a scatterplot
sym_counts$hpf<-as.numeric(as.character(sym_counts$hpf))
symb_plot<-sym_counts %>%
filter(!group=="Attached Recruit")%>%
droplevels()%>%
ggplot(., aes(x = hpf, y = cells.ind)) +
#geom_boxplot(outlier.size = 0) +
geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(5)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
ylim(0,9000)+
theme_classic() +
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14),
legend.text=element_text(size=12)
); symb_plot
#EGG: #8C510A
#EMBRYO: #DFC27D
#LARVAE: #80CDC1
#RECRUIT: #003C30
#ATTACHED: #BA55D3
Plot data as box plot
symb_plot2<-sym_counts %>%
filter(!group=="Attached Recruit")%>%
droplevels()%>%
ggplot(., aes(x = as.factor(hpf), y = cells.ind)) +
geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
#geom_smooth(method="loess", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.2)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"), guide="none")+
ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
ylim(0,9000)+
theme_classic() +
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); symb_plot2
Run ANOVA on cells per larvae by sampling point, specified by sequence of samples taken (life stage, hpf).
sym_ind_model_data<-sym_counts%>%
filter(!group=="Attached Recruit")%>%
droplevels()
sym_ind_model<-aov(cells.ind~lifestage, data=sym_ind_model_data)
summary(sym_ind_model)
## Df Sum Sq Mean Sq F value Pr(>F)
## lifestage 9 102932981 11436998 25.06 1.34e-11 ***
## Residuals 30 13689458 456315
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqPlot(residuals(sym_ind_model))
## [1] 33 30
leveneTest(residuals(sym_ind_model)~lifestage, data=sym_ind_model_data)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 9 1.7683 0.1166
## 30
Both normality and homogeneity of variance pass.
There is a significant effect of lifestage on cell densities. View posthoc comparisons for differences between lifestages.
emm = emmeans(sym_ind_model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
## lifestage emmean SE df lower.CL upper.CL .group
## Embryo (38 hpf) 1371 338 30 681 2061 A
## Egg (1 hpf) 1472 338 30 782 2161 A
## Embryo (5 hpf) 1831 338 30 1141 2521 A
## Embryo (65 hpf) 2646 338 30 1956 3335 AB
## Larvae (93 hpf) 2692 338 30 2002 3382 AB
## Larvae (163 hpf) 2848 338 30 2158 3538 AB
## Larvae (183 hpf) 3474 338 30 2784 4163 BC
## Metamorphosed Polyp (183 hpf) 4829 338 30 4139 5519 CD
## Larvae (231 hpf) 5142 338 30 4452 5831 D
## Metamorphosed Polyp (231 hpf) 6424 338 30 5734 7114 D
##
## Confidence level used: 0.95
## P value adjustment: tukey method for comparing a family of 10 estimates
## significance level used: alpha = 0.05
## NOTE: Compact letter displays can be misleading
## because they show NON-findings rather than findings.
## Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
pairs(emm)
## contrast estimate SE df
## Egg (1 hpf) - Embryo (38 hpf) 100.4 478 30
## Egg (1 hpf) - Embryo (5 hpf) -359.6 478 30
## Egg (1 hpf) - Embryo (65 hpf) -1174.0 478 30
## Egg (1 hpf) - Larvae (163 hpf) -1376.3 478 30
## Egg (1 hpf) - Larvae (183 hpf) -2002.0 478 30
## Egg (1 hpf) - Larvae (231 hpf) -3669.9 478 30
## Egg (1 hpf) - Larvae (93 hpf) -1220.4 478 30
## Egg (1 hpf) - Metamorphosed Polyp (183 hpf) -3357.6 478 30
## Egg (1 hpf) - Metamorphosed Polyp (231 hpf) -4952.2 478 30
## Embryo (38 hpf) - Embryo (5 hpf) -460.0 478 30
## Embryo (38 hpf) - Embryo (65 hpf) -1274.4 478 30
## Embryo (38 hpf) - Larvae (163 hpf) -1476.7 478 30
## Embryo (38 hpf) - Larvae (183 hpf) -2102.4 478 30
## Embryo (38 hpf) - Larvae (231 hpf) -3770.3 478 30
## Embryo (38 hpf) - Larvae (93 hpf) -1320.8 478 30
## Embryo (38 hpf) - Metamorphosed Polyp (183 hpf) -3458.0 478 30
## Embryo (38 hpf) - Metamorphosed Polyp (231 hpf) -5052.6 478 30
## Embryo (5 hpf) - Embryo (65 hpf) -814.4 478 30
## Embryo (5 hpf) - Larvae (163 hpf) -1016.7 478 30
## Embryo (5 hpf) - Larvae (183 hpf) -1642.4 478 30
## Embryo (5 hpf) - Larvae (231 hpf) -3310.3 478 30
## Embryo (5 hpf) - Larvae (93 hpf) -860.8 478 30
## Embryo (5 hpf) - Metamorphosed Polyp (183 hpf) -2998.0 478 30
## Embryo (5 hpf) - Metamorphosed Polyp (231 hpf) -4592.6 478 30
## Embryo (65 hpf) - Larvae (163 hpf) -202.3 478 30
## Embryo (65 hpf) - Larvae (183 hpf) -828.0 478 30
## Embryo (65 hpf) - Larvae (231 hpf) -2495.9 478 30
## Embryo (65 hpf) - Larvae (93 hpf) -46.4 478 30
## Embryo (65 hpf) - Metamorphosed Polyp (183 hpf) -2183.6 478 30
## Embryo (65 hpf) - Metamorphosed Polyp (231 hpf) -3778.2 478 30
## Larvae (163 hpf) - Larvae (183 hpf) -625.8 478 30
## Larvae (163 hpf) - Larvae (231 hpf) -2293.7 478 30
## Larvae (163 hpf) - Larvae (93 hpf) 155.9 478 30
## Larvae (163 hpf) - Metamorphosed Polyp (183 hpf) -1981.3 478 30
## Larvae (163 hpf) - Metamorphosed Polyp (231 hpf) -3575.9 478 30
## Larvae (183 hpf) - Larvae (231 hpf) -1667.9 478 30
## Larvae (183 hpf) - Larvae (93 hpf) 781.6 478 30
## Larvae (183 hpf) - Metamorphosed Polyp (183 hpf) -1355.6 478 30
## Larvae (183 hpf) - Metamorphosed Polyp (231 hpf) -2950.2 478 30
## Larvae (231 hpf) - Larvae (93 hpf) 2449.5 478 30
## Larvae (231 hpf) - Metamorphosed Polyp (183 hpf) 312.3 478 30
## Larvae (231 hpf) - Metamorphosed Polyp (231 hpf) -1282.3 478 30
## Larvae (93 hpf) - Metamorphosed Polyp (183 hpf) -2137.2 478 30
## Larvae (93 hpf) - Metamorphosed Polyp (231 hpf) -3731.8 478 30
## Metamorphosed Polyp (183 hpf) - Metamorphosed Polyp (231 hpf) -1594.6 478 30
## t.ratio p.value
## 0.210 1.0000
## -0.753 0.9988
## -2.458 0.3298
## -2.881 0.1554
## -4.191 0.0073
## -7.683 <.0001
## -2.555 0.2816
## -7.029 <.0001
## -10.368 <.0001
## -0.963 0.9923
## -2.668 0.2316
## -3.091 0.1013
## -4.401 0.0042
## -7.893 <.0001
## -2.765 0.1940
## -7.239 <.0001
## -10.578 <.0001
## -1.705 0.7842
## -2.128 0.5232
## -3.438 0.0469
## -6.930 <.0001
## -1.802 0.7288
## -6.276 <.0001
## -9.615 <.0001
## -0.423 1.0000
## -1.733 0.7685
## -5.225 0.0005
## -0.097 1.0000
## -4.571 0.0027
## -7.910 <.0001
## -1.310 0.9435
## -4.802 0.0014
## 0.326 1.0000
## -4.148 0.0082
## -7.486 <.0001
## -3.492 0.0415
## 1.636 0.8201
## -2.838 0.1690
## -6.176 <.0001
## 5.128 0.0006
## 0.654 0.9996
## -2.684 0.2249
## -4.474 0.0035
## -7.813 <.0001
## -3.338 0.0590
##
## P value adjustment: tukey method for comparing a family of 10 estimates
Output data to file.
sym_counts %>%
write_csv(., file = "Mcap2020/Output/Physiology/calculated_densities.csv")
First, test for correlation between symbiont cell density and larval volume to see if there is a relationship.
Generate data frame with summarized size and cell density information for each time point from eggs to metamorphosed recruits, because we have data for volume and counts for each sample. We do not include attached recruits here yet, because we cannot calculate densities per individual.
#read in data frame generated in previous chunk
sym_counts<-sym_counts%>%
dplyr::select(tube.ID, lifestage, group, hpf, cells.ind, cells.mm)
#grab size data
volume<-size%>%
group_by(tube.ID)%>%
summarise(mean_volume=mean(volume, na.rm=TRUE))
volume$tube.ID<-as.factor(volume$tube.ID)
sym_counts$hpf<-as.factor(sym_counts$hpf)
corr<-left_join(sym_counts, volume)
Generate number of symbiont cells per mm^2 area for each tube.
corr<-corr%>%
mutate(mean_volume_2=mean_volume*2)%>%
mutate(counts_volume=cells.ind/mean_volume)%>%
mutate(counts_volume=ifelse(is.na(counts_volume), cells.mm, counts_volume)) #add attached recruit data already calculated as cells per mm2
Plot correlation between cell counts (cells per individual) and volume (mm^3).
correlation<-corr %>%
filter(!group=="Attached Recruit")%>%
ggplot(., aes(x = mean_volume, y = cells.ind)) +
#geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black", fill="gray") +
geom_point(aes(fill=group), pch = 21, size=4) +
xlab(expression(bold(paste("Larval Size (mm"^2, ")")))) +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
xlab(expression(bold(paste("Individual Volume (mm"^3, ")"))))+
ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
#ylim(0, 9000)+
theme_classic() +
theme(
legend.position="none",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); correlation
Test relationship with a spearman correlation.
cor.test(corr$mean_volume, corr$cells.ind, method=c("spearman"))
##
## Spearman's rank correlation rho
##
## data: corr$mean_volume and corr$cells.ind
## S = 8834, p-value = 0.2895
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.1712946
There is not a significant correlation between volume and symbiont density.
Plot cells per mm^3 as a boxplot.
#order for creating a legend for all plots
corr$group <- factor(corr$group, levels = c("Egg", "Embryo", "Larvae", "Metamorphosed Polyp", "Attached Recruit"))
cells_size_plot<-corr %>%
filter(!group=="Attached Recruit")%>%
ggplot(., aes(x = hpf, y = counts_volume)) +
geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.4)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"), guide="none")+
scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"))+
ylab(expression(bold(paste("Volume-normalized cell density (mm"^-3,")"))))+
#ylim(2000, 35000)+
theme_classic() +
theme(
legend.position="top",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); cells_size_plot
#making a plot with a legend for use later on
#we are NOT using this plot for comparisons due to different units for attached recruits that cannot be compared.
legend_plot<-corr %>%
#filter(!group=="Attached Recruit")%>%
ggplot(., aes(x = hpf, y = counts_volume)) +
geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.4)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"), guide="none")+
scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"))+
ylab(expression(bold(paste("Symbiont cells mm"^-3))))+
#ylim(2000, 35000)+
theme_classic() +
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
)
Plot as linear relationship.
cells_size_plot2<-corr %>%
filter(!group=="Attached Recruit")%>%
ggplot(., aes(x = as.numeric(as.character(hpf)), y = counts_volume)) +
geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(0.4)) +
geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"), guide="none")+
scale_color_manual(name="Lifestage", values=c( "#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"))+
ylab(expression(bold(paste("Symbiont cells mm"^-3))))+
#ylim(2000, 35000)+
theme_classic() +
theme(
legend.position="right",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); cells_size_plot2
Analyze differences in normalized cell counts by timepoint.
model<-corr%>%
filter(!group=="Attached Recruit")%>%
droplevels()%>%
aov(counts_volume~lifestage, data=.)
qqPlot(residuals(model))
## [1] 33 31
corr%>%
filter(!group=="Attached Recruit")%>%
droplevels()%>%
leveneTest(residuals(model)~lifestage, data=.)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 9 1.4237 0.2223
## 30
summary(model)
## Df Sum Sq Mean Sq F value Pr(>F)
## lifestage 9 8.963e+09 995863544 25.87 8.92e-12 ***
## Residuals 30 1.155e+09 38493711
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
View posthoc differences.
emm = emmeans(model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
## lifestage emmean SE df lower.CL upper.CL .group
## Embryo (38 hpf) 11163 3102 30 4827 17498 A
## Egg (1 hpf) 14713 3102 30 8377 21048 A
## Embryo (5 hpf) 20447 3102 30 14112 26783 AB
## Larvae (163 hpf) 30491 3102 30 24156 36827 BC
## Larvae (231 hpf) 34707 3102 30 28372 41043 BCD
## Larvae (183 hpf) 34941 3102 30 28606 41277 BCD
## Embryo (65 hpf) 39524 3102 30 33188 45859 CDE
## Larvae (93 hpf) 46545 3102 30 40210 52881 DEF
## Metamorphosed Polyp (231 hpf) 53002 3102 30 46667 59338 EF
## Metamorphosed Polyp (183 hpf) 58545 3102 30 52210 64881 F
##
## Confidence level used: 0.95
## P value adjustment: tukey method for comparing a family of 10 estimates
## significance level used: alpha = 0.05
## NOTE: Compact letter displays can be misleading
## because they show NON-findings rather than findings.
## Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.
pairs(emm)
## contrast estimate SE df
## Egg (1 hpf) - Embryo (38 hpf) 3550 4387 30
## Egg (1 hpf) - Embryo (5 hpf) -5734 4387 30
## Egg (1 hpf) - Embryo (65 hpf) -24811 4387 30
## Egg (1 hpf) - Larvae (163 hpf) -15779 4387 30
## Egg (1 hpf) - Larvae (183 hpf) -20229 4387 30
## Egg (1 hpf) - Larvae (231 hpf) -19994 4387 30
## Egg (1 hpf) - Larvae (93 hpf) -31832 4387 30
## Egg (1 hpf) - Metamorphosed Polyp (183 hpf) -43832 4387 30
## Egg (1 hpf) - Metamorphosed Polyp (231 hpf) -38289 4387 30
## Embryo (38 hpf) - Embryo (5 hpf) -9284 4387 30
## Embryo (38 hpf) - Embryo (65 hpf) -28361 4387 30
## Embryo (38 hpf) - Larvae (163 hpf) -19328 4387 30
## Embryo (38 hpf) - Larvae (183 hpf) -23779 4387 30
## Embryo (38 hpf) - Larvae (231 hpf) -23544 4387 30
## Embryo (38 hpf) - Larvae (93 hpf) -35382 4387 30
## Embryo (38 hpf) - Metamorphosed Polyp (183 hpf) -47382 4387 30
## Embryo (38 hpf) - Metamorphosed Polyp (231 hpf) -41839 4387 30
## Embryo (5 hpf) - Embryo (65 hpf) -19077 4387 30
## Embryo (5 hpf) - Larvae (163 hpf) -10044 4387 30
## Embryo (5 hpf) - Larvae (183 hpf) -14494 4387 30
## Embryo (5 hpf) - Larvae (231 hpf) -14260 4387 30
## Embryo (5 hpf) - Larvae (93 hpf) -26098 4387 30
## Embryo (5 hpf) - Metamorphosed Polyp (183 hpf) -38098 4387 30
## Embryo (5 hpf) - Metamorphosed Polyp (231 hpf) -32555 4387 30
## Embryo (65 hpf) - Larvae (163 hpf) 9033 4387 30
## Embryo (65 hpf) - Larvae (183 hpf) 4582 4387 30
## Embryo (65 hpf) - Larvae (231 hpf) 4817 4387 30
## Embryo (65 hpf) - Larvae (93 hpf) -7021 4387 30
## Embryo (65 hpf) - Metamorphosed Polyp (183 hpf) -19021 4387 30
## Embryo (65 hpf) - Metamorphosed Polyp (231 hpf) -13478 4387 30
## Larvae (163 hpf) - Larvae (183 hpf) -4450 4387 30
## Larvae (163 hpf) - Larvae (231 hpf) -4216 4387 30
## Larvae (163 hpf) - Larvae (93 hpf) -16054 4387 30
## Larvae (163 hpf) - Metamorphosed Polyp (183 hpf) -28054 4387 30
## Larvae (163 hpf) - Metamorphosed Polyp (231 hpf) -22511 4387 30
## Larvae (183 hpf) - Larvae (231 hpf) 234 4387 30
## Larvae (183 hpf) - Larvae (93 hpf) -11604 4387 30
## Larvae (183 hpf) - Metamorphosed Polyp (183 hpf) -23604 4387 30
## Larvae (183 hpf) - Metamorphosed Polyp (231 hpf) -18061 4387 30
## Larvae (231 hpf) - Larvae (93 hpf) -11838 4387 30
## Larvae (231 hpf) - Metamorphosed Polyp (183 hpf) -23838 4387 30
## Larvae (231 hpf) - Metamorphosed Polyp (231 hpf) -18295 4387 30
## Larvae (93 hpf) - Metamorphosed Polyp (183 hpf) -12000 4387 30
## Larvae (93 hpf) - Metamorphosed Polyp (231 hpf) -6457 4387 30
## Metamorphosed Polyp (183 hpf) - Metamorphosed Polyp (231 hpf) 5543 4387 30
## t.ratio p.value
## 0.809 0.9979
## -1.307 0.9442
## -5.655 0.0001
## -3.597 0.0324
## -4.611 0.0024
## -4.558 0.0028
## -7.256 <.0001
## -9.991 <.0001
## -8.728 <.0001
## -2.116 0.5309
## -6.465 <.0001
## -4.406 0.0042
## -5.420 0.0003
## -5.367 0.0003
## -8.065 <.0001
## -10.800 <.0001
## -9.537 <.0001
## -4.348 0.0049
## -2.289 0.4238
## -3.304 0.0638
## -3.250 0.0719
## -5.949 0.0001
## -8.684 <.0001
## -7.421 <.0001
## 2.059 0.5677
## 1.045 0.9865
## 1.098 0.9812
## -1.600 0.8377
## -4.336 0.0050
## -3.072 0.1055
## -1.014 0.9890
## -0.961 0.9925
## -3.659 0.0278
## -6.395 <.0001
## -5.131 0.0006
## 0.053 1.0000
## -2.645 0.2412
## -5.380 0.0003
## -4.117 0.0089
## -2.698 0.2193
## -5.434 0.0003
## -4.170 0.0077
## -2.735 0.2051
## -1.472 0.8927
## 1.263 0.9543
##
## P value adjustment: tukey method for comparing a family of 10 estimates
Generate summary table of descriptive statistics.
#need to output to csv
corr%>%
group_by(group, hpf, lifestage)%>%
filter(!group=="Attached Recruit")%>%
droplevels()%>%
summarise(n=length(counts_volume),
Mean_sym_mm3=format(round(mean(counts_volume), 0), 0),
SE=format(round(sd(counts_volume)/sqrt(length(counts_volume)),0),0))%>%
rename(Lifestage=group, HPF=hpf)%>%
write_csv(., "Mcap2020/Output/Physiology/normalized_size_cells_summary.csv")
Plot as box plot.
recruit_size_plot<-corr %>%
filter(group=="Attached Recruit")%>%
ggplot(., aes(x = hpf, y = counts_volume)) +
geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.4)) +
xlab("Hours Post-Fertilization") +
scale_fill_manual(name="Lifestage", values=c("#BA55D3"), guide="none")+
scale_color_manual(name="Lifestage", values=c("#BA55D3"))+
ylab(expression(bold(paste("Surface area-normalized cell density (mm"^-2,")"))))+
#ylim(2000, 35000)+
theme_classic() +
theme(
legend.position="top",
axis.title=element_text(face="bold", size=14),
axis.text=element_text(size=12, color="black"),
legend.title=element_text(face="bold", size=14)
); recruit_size_plot
View summary of symbiont densities per unit surface area.
#need to output to csv
corr%>%
group_by(group, hpf, lifestage)%>%
filter(group=="Attached Recruit")%>%
droplevels()%>%
summarise(n=length(counts_volume),
Mean_sym_mm2=format(round(mean(counts_volume), 0), 0),
SE=format(round(sd(counts_volume)/sqrt(length(counts_volume)),0),0))%>%
rename(Lifestage=group, HPF=hpf)%>%
write_csv(., "Mcap2020/Output/Physiology/normalized_size_cells_summary_attached.csv")
Generate physiology panel with all variables of interest.
# extract the legend from one of the plots
legend <- get_legend(
# create some space to the left of the legend
cells_size_plot + theme(legend.position="right") + theme(legend.box.margin = margin(1,1,1,1))
)
#remove legends from plots
size_plot2<-size_plot2+theme(legend.position="none")
symb_plot2<-symb_plot2+theme(legend.position="none")
cells_size_plot_l<-cells_size_plot+theme(legend.position="none")
#assemble plots
all_plots<-plot_grid(size_plot2, symb_plot2, cells_size_plot_l, labels = c("A", "B", "C"), label_size=18, ncol=3, nrow=1, rel_heights= c(1,1,1), rel_widths = c(1,1,1), align="h")
all_plots_legend<-plot_grid(all_plots, legend, rel_widths = c(4, 0.5), ncol=2, nrow=1)
ggsave(file="Mcap2020/Figures/Physiology/Physiology_figure_all.png", all_plots_legend, dpi=300, width=24, height=6, units="in")
Early life history physiology
Generate a figure that has just the symbiont density metrics of interest: counts per individual.
# extract the legend from one of the plots
legend <- get_legend(
# create some space to the left of the legend
legend_plot + theme(legend.box.margin = margin(1,1,1,1))
)
symb_plot2b<-symb_plot2+theme(legend.position="none")+ theme(axis.title=element_text(size=14, face="bold"))
recruit_size_plot2<-recruit_size_plot+theme(legend.position="none")+theme(axis.title=element_text(size=10))+ylim(500,9000)
target_plots<- ggdraw(symb_plot2b) +
draw_plot(recruit_size_plot2, .16, .6, .35, .35) +
draw_plot_label(
c("A", "B"),
c(0.05, 0.2),
c(1, 0.96),
size = 16
);target_plots
target_plots_legend<-plot_grid(symb_plot2b, legend, rel_widths = c(4, 1.2), ncol=2, nrow=1)
ggsave(file="Mcap2020/Figures/Physiology/Physiology_figure_densities.png", target_plots_legend, dpi=300, width=8, height=6, units="in")
Early life history physiology
Generate a figure that has just the symbiont density metrics of interest: volume normalized counts.
# extract the legend from one of the plots
legend <- get_legend(
# create some space to the left of the legend
legend_plot + theme(legend.box.margin = margin(1,1,1,1))
)
cells_size_plotb<-cells_size_plot+theme(legend.position="none")+ theme(axis.title=element_text(size=14, face="bold"))+ylim(2000,85000)
recruit_size_plot2<-recruit_size_plot+theme(legend.position="none")+theme(axis.title=element_text(size=14))+ylim(0,8000)
#target_plots2<- ggdraw(cells_size_plotb) +
#draw_plot(recruit_size_plot2, .16, .6, .35, .35) +
#draw_plot_label(
# c("A", "B"),
#c(0.05, 0.2),
# c(1, 0.96),
#size = 16
#);target_plots2
target_plots_legend2<-plot_grid(cells_size_plotb, recruit_size_plot2, legend, labels=c("A", "B"), rel_widths = c(3,1.3, 1), ncol=3, nrow=1)
ggsave(file="Mcap2020/Figures/Physiology/Physiology_figure_densities_volume.png", target_plots_legend2, dpi=300, width=10, height=6, units="in")
Early life history physiology